﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ProjetS5
{
    public class Mover
    {
        public static List<Mover> allMovers = new List<Mover>();

        public Mover() 
            : this(Vector2.Zero, Vector2.Zero)
        {
        }
        public Mover(Vector2 Position, Vector2 Orientation)
            : this(Position, Orientation, 1.5f)
        {
        }
        public Mover(Vector2 Position, Vector2 Orientation, float Speed)
        {
            this.position = Position;
            this.orientation = Orientation;
            this.speed = Speed;
            toDraw = null;
        }
        /// <summary>
        /// Everybody
        /// </summary>
        public Vector2 position;
        /// <summary>
        /// Everybody
        /// </summary>
        public Vector2 orientation;
        /// <summary>
        /// Everybody
        /// </summary>
        public float speed;
        /// <summary>
        /// Everybody
        /// </summary>
        public Map mapPositionned;
        /// <summary>
        /// Everybody
        /// </summary>
        public Texture2D toDraw;
        public static GraphicsDevice device;

        public virtual void Draw(Game game, SpriteBatch spriteBatch)
        {
            if (toDraw != null)
            {
                spriteBatch.Draw(toDraw, new Vector2(position.X - toDraw.Width / 2, position.Y - toDraw.Height / 2), Color.White);
            }
        }
        public void Orientate(Vector2 direction, List<Texture2D> sprites)
        {
            if (direction.X == -1)
            {
                toDraw = sprites[3];
            }
            else if (direction.X == 1)
            {
                toDraw = sprites[1];
            }
            if (direction.Y == -1)
            {
                toDraw = sprites[0];
            }
            else if (direction.Y == 1 || toDraw == null)
            {
                toDraw = sprites[2];
            }
            if (direction != Vector2.Zero)
            {
                orientation = direction;
            }
        }
        public void Move(Vector2 direction, List<Texture2D> sprites)
        {
            if (direction.X == 0 || direction.Y == 0)
            {
                position += direction * speed;
            }
            else
            {
                position += direction * (float)Math.Sqrt(Math.Pow(speed, 2) / 2);
            }
            Orientate(direction, sprites);
        }
    }
}
